package com.fishingwithme.domain.anybiting;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.core.JsonProcessingException;

import com.fishingwithme.infrastructure.dtos.anybiting.MessageContentBody;
import com.fishingwithme.infrastructure.utils.CommonUtils;
import lombok.Data;
import lombok.experimental.Accessors;

@TableName(autoResultMap = true)
@Accessors(chain = true)
@Data
public class CircleMessage {
    private String id; // UUID
    private String cityCode;
    private Long bizId;
    private MessageType type; // CRM 或 CEM
    private SubType subType; // 具体子类型
    private Object content; // JSON格式的内容
    private Date timestamp;
    private String sender; // 发送者标识
    private Integer priority; // 消息优先级

    public void toJsonObj() {
        if(MessageContentBody.class.isAssignableFrom(this.content.getClass())) {
            MessageContentBody body = (MessageContentBody) this.content;
            body.format();
        }
    }

    public void toJsonString() {
        try {
            this.content = CommonUtils.objectMapper.writeValueAsString(this.content);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
